/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.bastian.hinterleitner;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import de.bastian.hinterleitner.tools.Constants;
import de.bastian.hinterleitner.tools.WatchYourCashActivity;
import de.hijacksoft.wyc.R;

/**
 *
 * @author basti
 */
public class Selection extends WatchYourCashActivity implements OnClickListener{

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.activity_selection);
        ((Button)findViewById(R.id.selection_time)).setOnClickListener(this);
        ((Button)findViewById(R.id.selection_cat)).setOnClickListener(this);
        ((Button)findViewById(R.id.selection_search)).setOnClickListener(this);
        ((Button)findViewById(R.id.selection_xml)).setOnClickListener(this);
        ((TextView)findViewById(R.id.selection_text_hijack)).setOnClickListener(this);
        
        initNav((LinearLayout)findViewById(R.id.selection_header), getString(R.string.more));
        initFooter(((LinearLayout)findViewById(R.id.selection_layout_bottom)));
        
        setResult(RESULT_OK);
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	super.onActivityResult(requestCode, resultCode, data);
    	if(resultCode == Constants.RESULT_KILLME)finish();
    }

    public void onClick(View view) {
        switch(view.getId()){
            case R.id.selection_time:
                startActivity(new Intent(this, Overview.class));
                break;
            case R.id.selection_cat:
                startActivity(new Intent(this, Categories.class));
                break;
            case R.id.selection_search:
                startActivity(new Intent(this, Search.class));
                break;
            case R.id.selection_xml:
                startActivity(new Intent(this, XmlActivity.class));
                break;
            case R.id.selection_text_hijack:
            	String url = getString(R.string.hijack);
            	if (!url.startsWith("http://") && !url.startsWith("https://"))
            		   url = "http://" + url;
            	Uri uri = Uri.parse(url);
    			try{
    				startActivity(new Intent(Intent.ACTION_VIEW, uri));
    			}catch(ActivityNotFoundException ex){
    				Log.e(getString(R.string.name), "couldnt start intent to go to webpage - "+ex.getMessage());
    			}
            	break;
        }
    }

	@Override
	public boolean hasOptionsMenu() {
		return false;
	}
}
